﻿using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace CharacterInc.IncrementCharacter
{
	internal class NumToChsOrRome
	{
		protected static int LowerChsToNumber(char c)
		{
			if (c <= '二')
			{
				if (c <= '七')
				{
					if (c == '一')
					{
						return 1;
					}
					if (c == '七')
					{
						return 7;
					}
				}
				else
				{
					if (c == '三')
					{
						return 3;
					}
					if (c == '九')
					{
						return 9;
					}
					if (c == '二')
					{
						return 2;
					}
				}
			}
			else if (c <= '八')
			{
				if (c == '五')
				{
					return 5;
				}
				if (c == '八')
				{
					return 8;
				}
			}
			else
			{
				if (c == '六')
				{
					return 6;
				}
				if (c == '四')
				{
					return 4;
				}
				if (c == '零')
				{
					return 0;
				}
			}
			return -1;
		}

		protected static int UpperChsToNumber(char c)
		{
			if (c <= '柒')
			{
				if (c <= '叁')
				{
					if (c == '伍')
					{
						return 5;
					}
					if (c == '叁')
					{
						return 3;
					}
				}
				else
				{
					if (c == '壹')
					{
						return 1;
					}
					if (c == '捌')
					{
						return 8;
					}
					if (c == '柒')
					{
						return 7;
					}
				}
			}
			else if (c <= '肆')
			{
				if (c == '玖')
				{
					return 9;
				}
				if (c == '肆')
				{
					return 4;
				}
			}
			else
			{
				if (c == '贰')
				{
					return 2;
				}
				if (c == '陆')
				{
					return 6;
				}
				if (c == '零')
				{
					return 0;
				}
			}
			return -1;
		}

		public static int LowerChsToUnit(char c)
		{
			if (c <= '亿')
			{
				if (c == '万')
				{
					return 10000;
				}
				if (c == '亿')
				{
					return 100000000;
				}
			}
			else
			{
				if (c == '十')
				{
					return 10;
				}
				if (c == '千')
				{
					return 1000;
				}
				if (c == '百')
				{
					return 100;
				}
			}
			return 1;
		}

		public static int UpperChsToUnit(char c)
		{
			if (c <= '亿')
			{
				if (c == '万')
				{
					return 10000;
				}
				if (c == '亿')
				{
					return 100000000;
				}
			}
			else
			{
				if (c == '仟')
				{
					return 1000;
				}
				if (c == '佰')
				{
					return 100;
				}
				if (c == '拾')
				{
					return 10;
				}
			}
			return 1;
		}

		public static int UpperChsToNum(string cnum)
		{
			cnum = Regex.Replace(cnum, "\\s+", "");
			int num = 1;
			int num2 = 1;
			int num3 = 1;
			int num4 = 0;
			for (int i = cnum.Length - 1; i > -1; i--)
			{
				num3 = NumToChsOrRome.UpperChsToUnit(cnum[i]);
				if (num3 > num)
				{
					num = num3;
					num2 = 1;
				}
				else if (num3 > num2)
				{
					num2 = num3;
				}
				else
				{
					num4 += num * num2 * NumToChsOrRome.UpperChsToNumber(cnum[i]);
				}
			}
			if (num3 == 10)
			{
				num4 += num;
			}
			return num4;
		}

		public static int LowerChsToNum(string cnum)
		{
			cnum = Regex.Replace(cnum, "\\s+", "");
			int num = 1;
			int num2 = 1;
			int num3 = 1;
			int num4 = 0;
			for (int i = cnum.Length - 1; i > -1; i--)
			{
				num3 = NumToChsOrRome.LowerChsToUnit(cnum[i]);
				if (num3 > num)
				{
					num = num3;
					num2 = 1;
				}
				else if (num3 > num2)
				{
					num2 = num3;
				}
				else
				{
					num4 += num * num2 * NumToChsOrRome.LowerChsToNumber(cnum[i]);
				}
			}
			if (num3 == 10)
			{
				num4 += num;
			}
			return num4;
		}

		public static string NumberToLowerChinese(int Val)
		{
			string text = string.Empty;
			string text2 = Val.ToString();
			string text3 = text2.Substring(0, 1);
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text3);
			if (num <= 856466825u)
			{
				if (num <= 822911587u)
				{
					if (num != 806133968u)
					{
						if (num == 822911587u)
						{
							if (text3 == "4")
							{
								text = "四";
								goto IL_18B;
							}
						}
					}
					else if (text3 == "5")
					{
						text = "五";
						goto IL_18B;
					}
				}
				else if (num != 839689206u)
				{
					if (num == 856466825u)
					{
						if (text3 == "6")
						{
							text = "六";
							goto IL_18B;
						}
					}
				}
				else if (text3 == "7")
				{
					text = "七";
					goto IL_18B;
				}
			}
			else if (num <= 906799682u)
			{
				if (num != 873244444u)
				{
					if (num == 906799682u)
					{
						if (text3 == "3")
						{
							text = "三";
							goto IL_18B;
						}
					}
				}
				else if (text3 == "1")
				{
					text = "一";
					goto IL_18B;
				}
			}
			else if (num != 923577301u)
			{
				if (num != 1007465396u)
				{
					if (num == 1024243015u)
					{
						if (text3 == "8")
						{
							text = "八";
							goto IL_18B;
						}
					}
				}
				else if (text3 == "9")
				{
					text = "九";
					goto IL_18B;
				}
			}
			else if (text3 == "2")
			{
				text = "二";
				goto IL_18B;
			}
			text = "零";
			IL_18B:
			if (text2.Length > 1)
			{
				switch (text2.Length)
				{
				case 2:
				case 6:
					text += "十";
					break;
				case 3:
				case 7:
					text += "百";
					break;
				case 4:
					text += "千";
					break;
				case 5:
					text += "万";
					break;
				default:
					text = (text ?? "");
					break;
				}
				Val = int.Parse(text2.Substring(1, text2.Length - 1));
				text += NumToChsOrRome.NumberToLowerChinese(Val);
			}
			if (text.Last<char>() == '零')
			{
				text = text.Remove(text.Length - 1, 1);
			}
			return text;
		}

		public static string NumberToUpperChinese(int Val)
		{
			string text = string.Empty;
			string text2 = Val.ToString();
			string text3 = text2.Substring(0, 1);
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text3);
			if (num <= 856466825u)
			{
				if (num <= 822911587u)
				{
					if (num != 806133968u)
					{
						if (num == 822911587u)
						{
							if (text3 == "4")
							{
								text = "肆";
								goto IL_18B;
							}
						}
					}
					else if (text3 == "5")
					{
						text = "伍";
						goto IL_18B;
					}
				}
				else if (num != 839689206u)
				{
					if (num == 856466825u)
					{
						if (text3 == "6")
						{
							text = "陆";
							goto IL_18B;
						}
					}
				}
				else if (text3 == "7")
				{
					text = "柒";
					goto IL_18B;
				}
			}
			else if (num <= 906799682u)
			{
				if (num != 873244444u)
				{
					if (num == 906799682u)
					{
						if (text3 == "3")
						{
							text = "叁";
							goto IL_18B;
						}
					}
				}
				else if (text3 == "1")
				{
					text = "壹";
					goto IL_18B;
				}
			}
			else if (num != 923577301u)
			{
				if (num != 1007465396u)
				{
					if (num == 1024243015u)
					{
						if (text3 == "8")
						{
							text = "捌";
							goto IL_18B;
						}
					}
				}
				else if (text3 == "9")
				{
					text = "玖";
					goto IL_18B;
				}
			}
			else if (text3 == "2")
			{
				text = "贰";
				goto IL_18B;
			}
			text = "零";
			IL_18B:
			if (text2.Length > 1)
			{
				switch (text2.Length)
				{
				case 2:
				case 6:
					text += "拾";
					break;
				case 3:
				case 7:
					text += "佰";
					break;
				case 4:
					text += "仟";
					break;
				case 5:
					text += "万";
					break;
				default:
					text = (text ?? "");
					break;
				}
				Val = int.Parse(text2.Substring(1, text2.Length - 1));
				text += NumToChsOrRome.NumberToUpperChinese(Val);
			}
			if (text.Last<char>() == '零')
			{
				text = text.Remove(text.Length - 1, 1);
			}
			return text;
		}
	}
}
